]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
searchDisplay: don't create useless SearchResult's
authorMaxim Ermilov <zaspire@rambler.ru>
Mon, 21 Mar 2011 22:53:07 +0000 (01:53 +0300)
committerMaxim Ermilov <zaspire@rambler.ru>
Mon, 21 Mar 2011 23:50:32 +0000 (02:50 +0300)
average constructing time for 1 SearchResult is 3 ms.
It give > 400 result on query like 'a' (on my machine).
https://bugzilla.gnome.org/show_bug.cgi?id=645313

js/ui/iconGrid.js
js/ui/searchDisplay.js

index 3cdc712a747eb3ca9a57bc75093664525735b2f7..c6deb1904a34c9c923e5056d5215c8ca8231e57d 100644 (file)
@@ -281,6 +281,10 @@ IconGrid.prototype = {
         }
     },
 
+    childrenInRow: function(rowWidth) {
+        return this._computeLayout(rowWidth)[0];
+    },
+
     _computeLayout: function (forWidth) {
         let nColumns = 0;
         let usedWidth = 0;
index 81fd89b1929247208fe092d23fc9651920b1735d..f3d463a941a8767b7a55847eb3277bcd5e65bdbe 100644 (file)
@@ -5,6 +5,7 @@ const Lang = imports.lang;
 const Gettext = imports.gettext.domain('gnome-shell');
 const _ = Gettext.gettext;
 const Gtk = imports.gi.Gtk;
+const Meta = imports.gi.Meta;
 const St = imports.gi.St;
 
 const DND = imports.ui.dnd;
@@ -104,8 +105,30 @@ GridSearchResults.prototype = {
         this._grid = new IconGrid.IconGrid({ rowLimit: MAX_SEARCH_RESULTS_ROWS,
                                              xAlign: St.Align.START });
         this.actor = new St.Bin({ x_align: St.Align.START });
+
         this.actor.set_child(this._grid.actor);
         this.selectionIndex = -1;
+        this._width = 0;
+        this.actor.connect('notify::width', Lang.bind(this, function() {
+            this._width = this.actor.width;
+            Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
+                this._tryAddResults();
+            }));
+        }));
+        this._notDisplayedResult = [];
+        this._terms = [];
+    },
+
+    _tryAddResults: function() {
+        let canDisplay = this._grid.childrenInRow(this._width) * MAX_SEARCH_RESULTS_ROWS
+                         - this._grid.visibleItemsCount();
+
+        for (let i = Math.min(this._notDisplayedResult.length, canDisplay); i > 0; i--) {
+            let result = this._notDisplayedResult.shift();
+            let meta = this.provider.getResultMeta(result);
+            let display = new SearchResult(this.provider, meta, this._terms);
+            this._grid.addItem(display.actor);
+        }
     },
 
     getVisibleResultCount: function() {
@@ -113,15 +136,15 @@ GridSearchResults.prototype = {
     },
 
     renderResults: function(results, terms) {
-        for (let i = 0; i < results.length; i++) {
-            let result = results[i];
-            let meta = this.provider.getResultMeta(result);
-            let display = new SearchResult(this.provider, meta, terms);
-            this._grid.addItem(display.actor);
-        }
+        // copy the lists
+        this._notDisplayedResult = results.slice(0);
+        this._terms = terms.slice(0);
+        this._tryAddResults();
     },
 
     clear: function () {
+        this._terms = [];
+        this._notDisplayedResult = [];
         this._grid.removeAll();
         this.selectionIndex = -1;
     },